<?php
/**
 * WpAbstractS.php
 * 
 * This file contains the WpAbstractS class, the abstract base class for simple object representations
 * of a table rows.
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage dataaccess.wpdatex
 */

require_once(dirname(__FILE__).'/SimpleDatexS.php');

/**
 * An abstract helper class for SimpleDatexS
 * 
 * The WpAbstractS class is an abstract class providing basic functionality for all classes 
 * based on SimpleDatexS. It expects the class property $_arrFields to be set by child classes in the following format: 
 * 
 * <code>
 * class MyData extends WpAbstractS
 * {
 * 		//Filling the fields array. Only two types are supported (string and number)!
 * 		protected $_arrFields = array(
 * 			'field1' => 'number',
 * 			'field2' => 'string',
 * 			...
 * 		);
 * 
 * 		//Filling the vtypes array to be used for validation
 * 		protected $_arrVTypes = array(
 * 			'field1' => 'not_null',
 * 			'field2' => 'string_not_empty'
 * 		);
 * 
 * 		//Other functions to implement:
 * 		public function getPkField() {
 *         return 'field1';
 *      }
 *      
 *      public function getTable() {
 *      	return 'MyData';
 *      }
 * }
 * </code>
 *   
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage dataaccess.wpdatex
 */
abstract class WpAbstractS extends SimpleDatexS
{
	/**
	 * @var The array containing fieldnames and types (string or number). To re-assigned by child classes!
	 */
	protected $_arrFields = array();
	
	/** 
	 * @var The array containing fieldnames and filters to be used for filtering the value
	 */
	protected $_arrFilters = array();
	
	/** 
	 * @var The array containing fieldnames and vtypes to be used for validation
	 */
	protected $_arrVTypes = array();
	
    /**
     * @see SimpleDatexS::getFieldType()
     */
    public function getFieldType($fieldname) {
         if (array_key_exists($fieldname, $this->_arrFields)) {
        	return $this->_arrFields[$fieldname];
        }
		
		return '';
    }
    
    /**
     * @see SimpleDatexS::getFields()
     */
    public function getFields() {
        return array_keys($this->_arrFields);
    }
    
    /**
     * @see SimpleDatexS::getFilter()
     */
    public function getFilter($fieldname) {
        if (!array_key_exists($fieldname, $this->_arrFilters)) {
			return '';
		}
		
		return $this->_arrFilters[$fieldname];
    }
    
    /**
	 * @see SimpleDatexS::getVType()
	 */
	public function getVType($fieldname) {
		if (!array_key_exists($fieldname, $this->_arrVTypes)) {
			return '';
		}
		
		return $this->_arrVTypes[$fieldname];
	}
}

/* End of file WpAbstractS.php */
/* Location: ./wildpack/dataaccess/wpdatex/WpAbstractS.php */ 